import java.io.*;
import java.util.*;

public class Client {

	public static void main(String args[])
	{
	
	Factory f1=Factory.getFactory(Factory.FRENCH);//crearea fabricii de obiecte in format francez
	Factory f2=Factory.getFactory(Factory.SUA);//crearea fabricii de obiecte in format american
	ArrayList <Entry> agenda=new ArrayList<Entry>();
    //lista cu toate intrarile din agenda	
	String op="";
	do
	{
		System.out.flush();
		System.out.println("********************************************");
		System.out.println("For adding your personal Informations please type - I");
		System.out.println("For adding a new Person  please type - P");
		System.out.println("For adding a new Task  please type - T");
		System.out.println("For Deleting a task  please type - D");
		System.out.println("For deleting a Contact person  please type - C");
		System.out.println("For displaying all the content of the agenda  please type - W");
		System.out.println("For exiting the program  please type - E");
		System.out.println("\n");
		System.out.println("Thank you for using our program, have a nice day ^_^\n");
		System.out.println("********************************************");
		System.out.println("\n");
		BufferedReader tastatura=new BufferedReader(new InputStreamReader(System.in));
		try
		{
	
		  System.out.println("Please type your option from the list above");
		  op=tastatura.readLine().toUpperCase();
		  if(op.charAt(0)=='I')//adaugarea datelor personale
		  {
			  System.out.println("Please enter your name: ");
			  String name=tastatura.readLine();
			  System.out.println("Please enter the number of your street: ");
			  Integer streetNr=Integer.parseInt(tastatura.readLine());
			  System.out.println("Please enter the name of your street: ");
			  String streetName=tastatura.readLine();
			  System.out.println("Please enter the name of your city: ");
			  String town=tastatura.readLine();
			  System.out.println("Please enter your zipcode");
			  Integer code=Integer.parseInt(tastatura.readLine());
			  System.out.println("Please enter your phone number");
			  String number=tastatura.readLine();
			  System.out.println("~ Please type in which format do you want your data to apear ~");
			  System.out.println("F - for french format\n");
			  System.out.println("A - for american format");
			  String option="";
			  option=tastatura.readLine().toUpperCase();
			  Address a;
			  PhoneNumber p;
			  if(option=="F")
			  {
				  a=f1.getAddress(streetNr, streetName, town, code);
				  p=f1.getPhoneNumber(number);
			  }
			  if(option=="A")
			  {
				  a=f2.getAddress(streetNr, streetName, town, code);
				  p=f2.getPhoneNumber(number);
				  
			  }
			  a=f2.getAddress(streetNr, streetName, town, code);
			  p=f2.getPhoneNumber(number);
			  Entry e=PersonalEntry.getInstance(name, a, p);
			  agenda.add(e);
			 
		  }
			else
				if(op.charAt(0)=='P')
				{
					System.out.println("Please enter the name of the contact you want to add: ");
					  String name=tastatura.readLine();
					  System.out.println("Please enter the number of the street: ");
					  Integer streetNr=Integer.parseInt(tastatura.readLine());
					  System.out.println("Please enter the name of the street: ");
					  String streetName=tastatura.readLine();
					  System.out.println("Please enter the name of the city: ");
					  String town=tastatura.readLine();
					  System.out.println("Please enter the zipcode: ");
					  Integer code=Integer.parseInt(tastatura.readLine());
					  System.out.println("Please enter the phone number: ");
					  String number=tastatura.readLine();
					  System.out.println("~ Please type in which format do you want your data to apear ~");
					  System.out.println("F - for french format\n");
					  System.out.println("A - for american format");
					  String option="";
					  option=tastatura.readLine().toUpperCase();
					  Address a;
					  PhoneNumber p;
					  if(option=="F")
					  {
						  a=f1.getAddress(streetNr, streetName, town, code);
						  p=f1.getPhoneNumber(number);
					  }
					  if(option=="A")
					  {
						  a=f2.getAddress(streetNr, streetName, town, code);
						  p=f2.getPhoneNumber(number);
						  
					  }
					  a=f2.getAddress(streetNr, streetName, town, code);
					  p=f2.getPhoneNumber(number);
					  Entry e=new PhoneBookEntry(name, a, p);
					  agenda.add(e);
				}
				else
			    if(op.charAt(0)=='T')
			    {
			    	 System.out.println("Please enter the name of the task:");
					  String name=tastatura.readLine();
					  System.out.println("Please enter the day of the task: ");
					  Integer day=Integer.parseInt(tastatura.readLine());
					  System.out.println("Please enter the mounth of the task: ");
					  Integer month=Integer.parseInt(tastatura.readLine());
					  System.out.println("Please enter the year of the task: ");
					  Integer year=Integer.parseInt(tastatura.readLine());
					  System.out.println("~ Please type in which format do you want your data to apear ~");
					  System.out.println("F - for french format\n");
					  System.out.println("A - for american format");
					  String option="";
					  option=tastatura.readLine().toUpperCase();
					  Date d;
					  if(option=="F")
					  {
					    d=f1.getDate(day, month, year);
					  }
					  if(option=="A")
					  {
						 d=f2.getDate(day, month, year);
						  
					  }
					   d=f2.getDate(day, month, year);
					  Entry e=new TaskEntry(name,d);
					  agenda.add(e);
					  
			    	
			    }
			    else
			    	if(op.charAt(0)=='C')
			    	{
			    		System.out.println("Please enter the name of the person which dates you want to delete ");
			    		String name=tastatura.readLine();
			    		int index=-1;
			    		for(int i=0;i<agenda.size();i++)
						{
							Entry e=agenda.get(i).copy();
							if(e.getName().equals(name))
							{
								index=i;
							}
						}
			    		if(index!=-1)
			    		{
			    			agenda.remove(index);
			    			System.out.println("SUCCES! you deleted the person "+name+" from the agenda");
			    			
			    		}
			    		else
			    		{
			    			System.out.println("ERROR! no date were found about "+name+" in the agenda");
			    		}
			    		
			    	}
			    	else
			    		if(op.charAt(0)=='D')
			    		{
			    			System.out.println("Please enter the name of the task");
				    		String name=tastatura.readLine();
				    		int index=-1;
				    		for(int i=0;i<agenda.size();i++)
							{
								Entry e=agenda.get(i).copy();
								if(e.getName().equals(name))
								{
									index=i;
								}
							}//se cauta sa se vada daca exista inregistrea 
				    		if(index!=-1)
				    		{
				    			agenda.remove(index);
				    			System.out.println("SUCCES! you deleted the task "+name+" from the agenda ");
				    			
				    		}
				    		else
				    		{
				    			System.out.println("ERROR! no date were found about "+name+" in the agenda");
				    		}
			    		}
			    		else
				if(op.charAt(0)=='W')
				{
					for(int i=0;i<agenda.size();i++)
					{
						System.out.println(agenda.get(i).copy());
					}
				}
						
		}
		catch(IOException e)
		{
			e.printStackTrace();
		}
		
	}
	while(op.charAt(0)!='X');
}
}

